package com.tiancheng.trade.merchant.service.impl;

import cn.hutool.core.text.StrBuilder;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tiancheng.trade.commom.core.data.PageInfo;
import com.tiancheng.trade.commom.core.data.Result;
import com.tiancheng.trade.commom.core.enums.PaymentChannelEnum;
import com.tiancheng.trade.commom.web.feign.PaymentFeignService;
import com.tiancheng.trade.commom.web.model.request.QueryOrderMerchantReqVO;
import com.tiancheng.trade.commom.web.model.response.QueryOrderMerchantResVO;
import com.tiancheng.trade.merchant.dto.responsedto.MerchantWithChannelDTO;
import com.tiancheng.trade.commom.web.model.response.PaymentChannelResponseDTO;
import com.tiancheng.trade.merchant.enums.*;
import com.tiancheng.trade.merchant.exception.BusinessException;
import com.tiancheng.trade.merchant.mapper.MerchantMapper;
import com.tiancheng.trade.merchant.mapper.MerchantPaymentChannelMapper;
import com.tiancheng.trade.merchant.mapper.OrganizationMapper;
import com.tiancheng.trade.merchant.mapper.ProductMapper;
import com.tiancheng.trade.merchant.model.Merchant;
import com.tiancheng.trade.merchant.model.MerchantPaymentChannel;
import com.tiancheng.trade.merchant.model.Organization;
import com.tiancheng.trade.merchant.model.Product;
import com.tiancheng.trade.merchant.service.IMerchantService;
import com.tiancheng.trade.merchant.util.ExcelUtil;
import com.tiancheng.trade.merchant.util.UserUtils;
import com.tiancheng.trade.merchant.util.cache.MerchantCache;
import com.tiancheng.trade.merchant.vo.merchant.*;
import com.tiancheng.trade.merchant.vo.product.SettlementRuleVO;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class MerchantService extends ServiceImpl<MerchantMapper,Merchant> implements IMerchantService {

    @Autowired
    private MerchantMapper merchantMapper;

    @Autowired
    private OrganizationMapper organizationMapper;

    @Autowired
    private ProductMapper productMapper;

    @Autowired
    private MerchantPaymentChannelMapper channelMapper;

    @Autowired
    private PaymentFeignService paymentFeignService;
    @Resource
    private MerchantCache merchantCache;

    public Merchant findById(Long id) throws BusinessException {
        Merchant merchant = merchantMapper.selectById(id);
        if (null != merchant) {

            //merchant.setAccountTypeName(MerchantAccountTypeEnum.getDescByCode(merchant.getAccountType()));
            QueryWrapper<MerchantPaymentChannel> conditions = new QueryWrapper<>();
            conditions.eq("merchant_code", merchant.getMerchantCode());
            conditions.eq("is_delete", "0");
            List<MerchantPaymentChannel> list = channelMapper.selectList(conditions);

            Result<List<PaymentChannelResponseDTO>> channelBOList = paymentFeignService.getAllChannel();
            if (channelBOList.getRet() == 0 && !channelBOList.getData().isEmpty()) {
                for (MerchantPaymentChannel channel : list) {
                    if (StringUtils.isNotEmpty(channel.getPaymentChannelCode())) {
                        String channelName = channelBOList.getData().stream().filter(c -> c.getPaymentChannelCode()
                                .equals(channel.getPaymentChannelCode())).findFirst()
                                .map(PaymentChannelResponseDTO::getPaymentChannelName).orElse("");
                        channel.setPaymentChannelName(channelName);
                    }
                }
            }

            merchant.setChannelList(list);
            QueryWrapper<Organization> orgConditions = new QueryWrapper<>();
            orgConditions.eq("is_delete", "0");
            if (StringUtils.isNotEmpty(merchant.getOrganizationCode())) {
                orgConditions.eq("organization_code", merchant.getOrganizationCode());
                Organization organization = organizationMapper.selectOne(orgConditions);
                merchant.setOrganizationName(organization.getOrganizationName());
            }
            if (StringUtils.isNotEmpty(merchant.getRevenueType())) {
                merchant.setRevenueTypeName(RevenueTypeEnum.getRevenueTypeNameByCode(merchant.getRevenueType()));
            }
        }
        return merchant;
    }

    @Override
    public PageInfo<Merchant> getMerchantPage(GetPageMerchantVO merchantVO) throws BusinessException {
        Page<Merchant> page = new Page<>();
        page.setCurrent(merchantVO.getCurrentPage());
        page.setSize(merchantVO.getPageSize());
        IPage<Merchant> pageresult = merchantMapper.getMerchantPage(page, merchantVO);
        PageInfo.Pagination pagination = new PageInfo.Pagination(merchantVO.getCurrentPage(), merchantVO.getPageSize(), page.getTotal());
        List<Merchant> list = pageresult.getRecords();
//        list.forEach(merchant -> {
//            if (StringUtils.isNotEmpty(merchant.getAccountType())) {
//                merchant.setAccountTypeName(MerchantAccountTypeEnum.getDescByCode(merchant.getAccountType()));
//                if (StringUtils.isNotEmpty(merchant.getRevenueType())) {
//                    merchant.setRevenueTypeName(RevenueTypeEnum.getRevenueTypeNameByCode(merchant.getRevenueType()));
//                }
//            }
//        });
        return new PageInfo<>(list, pagination);
    }

    @Override
    public List<Merchant> findList(GetMerchantVO merchantVO) throws BusinessException {
        List<Merchant> list = findBaseMerchantList(merchantVO);
        List<MerchantPaymentChannel> merchantChannelList = null;
        Result<List<PaymentChannelResponseDTO>> channelBOList = paymentFeignService.getAllChannel();
        List<PaymentChannelResponseDTO> channelList = new ArrayList<PaymentChannelResponseDTO>();
        if (channelBOList.getRet() == 0) {
            channelList = channelBOList.getData();
        }
        if (CollectionUtils.isNotEmpty(list)) {
            List<String> listId = list.stream().map(Merchant::getMerchantCode).collect(Collectors.toList());
            merchantChannelList = channelMapper.getChannelByMerchantCode(listId);
            // 处理渠道名称
            if (CollectionUtils.isNotEmpty(merchantChannelList)) {
                for (MerchantPaymentChannel channel : merchantChannelList) {
                    if (StringUtils.isNotEmpty(channel.getPaymentChannelCode()) && CollectionUtils.isNotEmpty(channelList)) {
                        String channelName = channelList.stream().filter(c -> c.getPaymentChannelCode().equals(channel.getPaymentChannelCode()))
                                .findFirst().map(PaymentChannelResponseDTO::getPaymentChannelName).orElse("");
                        channel.setPaymentChannelName(channelName);
                    }
                }
            }

            for (Merchant merchant : list) {
                /*if (StringUtils.isNotEmpty(merchant.getAccountType())) {
                    merchant.setAccountTypeName(MerchantAccountTypeEnum.getDescByCode(merchant.getAccountType()));
                }*/
                if (CollectionUtils.isNotEmpty(merchantChannelList)) {
                    List<MerchantPaymentChannel> channels = merchantChannelList.stream().filter(x -> x.getMerchantCode().equals(merchant.getMerchantCode())).collect(Collectors.toList());
                    merchant.setChannelList(channels);
                }
            }
        }
        return list;
    }

    /**
     * 查询商户主表
     *
     * @param merchantVO
     * @return
     */
    private List<Merchant> findBaseMerchantList(GetMerchantVO merchantVO) {
        QueryWrapper<Merchant> conditions = new QueryWrapper<>();
        conditions.eq("is_delete", "0");
        if (StringUtils.isNotEmpty(merchantVO.getOrganizationCode())) {
            conditions.eq("organization_code", merchantVO.getOrganizationCode());
        }
        if (StringUtils.isNotEmpty(merchantVO.getMerchantCode())) {
            conditions.likeLeft("merchant_code", merchantVO.getMerchantCode());
        }
        if (StringUtils.isNotEmpty(merchantVO.getMerchantName())) {
            conditions.likeLeft("merchant_name", merchantVO.getMerchantName());
        }
        return merchantMapper.selectList(conditions);
    }

    @Override
    public Merchant findMerchant(GetMerchantVO merchantVO) throws BusinessException {
        List<Merchant> list = findBaseMerchantList(merchantVO);
        Merchant merchant = new Merchant();
        /*if (CollectionUtils.isNotEmpty(list)) {
            merchant = list.get(0);
            if (StringUtils.isNotEmpty(merchant.getAccountType())) {
                merchant.setAccountTypeName(MerchantAccountTypeEnum.getDescByCode(merchant.getAccountType()));
            }
        }*/
        return merchant;
    }

    @Override
    public Merchant findMerchantOrg(GetPageMerchantVO merchantVO) throws BusinessException {
        List<Merchant> list = merchantMapper.findMerchantOrg(merchantVO);
        Merchant merchant = new Merchant();
        /*if (CollectionUtils.isNotEmpty(list)) {
            merchant = list.get(0);
            if (StringUtils.isNotEmpty(merchant.getAccountType())) {
                merchant.setAccountTypeName(MerchantAccountTypeEnum.getDescByCode(merchant.getAccountType()));
            }
        }*/
        return merchant;
    }

//    public void test() {
//        QueryWrapper<Merchant> conditions = new QueryWrapper<>();
//        conditions.eq("merchant_code", "");
//        List<Merchant> mm = merchantMapper.selectList(conditions);
//        for (Merchant merchant : mm) {
//            String content = merchant.getMerchantName() + String.valueOf(merchant.getCreatedDt()).substring(0, 19);
//            merchant.setMerchantCode(DigestUtils.md5DigestAsHex(content.getBytes()).toUpperCase());
//            merchantMapper.updateById(merchant);
//        }
//    }

    @Transactional(rollbackFor = Exception.class)
    public int add(Merchant merchant) throws BusinessException {

        //String createBy = UserUtils.currentUserId();
        merchant.setCreatedBy("0");
        merchant.setCreatedDt(LocalDateTime.now());
        // 如果没有指定merchantCode 则自动生成
        if (StringUtils.isEmpty(merchant.getMerchantCode())) {
            // 拼接creatTime时间戳(秒)后进行MD5运算 防止同名
            String content = merchant.getMerchantName() + String.valueOf(merchant.getCreatedDt()).substring(0, 19);
            merchant.setMerchantCode(DigestUtils.md5DigestAsHex(content.getBytes()).toUpperCase());
        }
//        List<Merchant> merchantList = findMerchantByCodeName(merchant);
//        Assert.isTrue(CollectionUtils.isEmpty(merchantList), "此商户编号或名称已存在");

        if(merchant.getMerchantType().equals("3")){
            // 小微商户，使用负责人身份证那个号码判断重复
            final long count = this.count(new LambdaQueryWrapper<Merchant>().eq(Merchant::getLegalIdcardNo, merchant.getLegalIdcardNo()));
            Assert.isTrue(count==0, "此负责人已注册过，不能重复注册！");
        }else{
            // 使用统一社会信用代码/多合一营业执照
            final long count = this.count(new LambdaQueryWrapper<Merchant>().eq(Merchant::getShopLic, merchant.getShopLic()));
            Assert.isTrue(count==0, "该企业/机构已注册过不能重复注册！");
        }

        int a = merchantMapper.insert(merchant);
        List<MerchantPaymentChannel> list = merchant.getChannelList();

        // 新增商户渠道信息
        if (CollectionUtils.isNotEmpty(list)) {
            // 检查多渠道时被使用渠道是否只有一个
            long channelUsedNum = list.stream().filter(s -> MerchantPayChannelUsedEnum.USED.getCode().equals(s.getUsed())).count();
            Assert.isTrue(channelUsedNum < 2, "一个商户只能有一条被使用的渠道");

            list.forEach(mer -> {
                mer.setMerchantCode(merchant.getMerchantCode());
                mer.setCreatedDt(LocalDateTime.now());
                mer.setCreatedBy("0");
            });
            channelMapper.insertBatch(list);
        }
        return a;
    }

    /**
     * 修改商户信息时，先删除渠道信息，再重新保存
     * 同时修改清分规则中的商户名称
     *
     * @param merchant
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public int update(Merchant merchant) throws BusinessException {

        SettlementRuleVO settlementRule = new SettlementRuleVO();
        settlementRule.setMerchantCode(merchant.getMerchantCode());
        settlementRule.setMerchantName(merchant.getMerchantName());
        Merchant merchantVO = new Merchant();
        merchantVO.setId(merchant.getId());
        merchantVO.setMerchantName(merchant.getMerchantName());
        String currentUserId = UserUtils.currentUserId();
        List<Merchant> merchantList = findMerchantByCodeName(merchant);
        Assert.isTrue(CollectionUtils.isEmpty(merchantList), "此商户编号或名称已存在");
        merchant.setLastUpdBy(currentUserId);
        merchant.setLastUpdDt(LocalDateTime.now());
        int a = merchantMapper.updateById(merchant);
        List<MerchantPaymentChannel> channelList = merchant.getChannelList();
        if (CollectionUtils.isNotEmpty(channelList)) {
            // 检查多渠道时被使用渠道是否只有一个
            long channelUsedNum = channelList.stream().filter(s -> MerchantPayChannelUsedEnum.USED.getCode().equals(s.getUsed())).count();
            Assert.isTrue(channelUsedNum < 2, "一个商户只能有一条被使用的渠道");


            List<String> listId = channelList.stream().map(MerchantPaymentChannel::getMerchantCode).collect(Collectors.toList());
            channelMapper.updateDelBatch(listId);
            channelList.forEach(channel -> {
                channel.setId(null);
                channel.setMerchantCode(merchant.getMerchantCode());
                channel.setCreatedBy(currentUserId);
                channel.setCreatedDt(LocalDateTime.now());
                merchantCache.isExistCachePaymentMerchant(merchant.getMerchantCode(), channel.getPaymentChannelCode()).ifPresent(b -> {
                    if (b) {
                        merchantCache.delCachePaymentMerchant(merchant.getMerchantCode(), channel.getPaymentChannelCode());
                    }
                });

            });
            channelMapper.insertBatch(channelList);
        }
//        settlementRuleFeignService.updateMerchantName(settlementRule);
        return a;
    }

    /**
     * 删除商户时判断当前商户是否关联产品
     * 删除商户信息时，同时删除商户渠道信息
     *
     * @param id
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public int remove(Long id) {

        Merchant merchant = merchantMapper.selectById(id);

        Assert.notNull(merchant, "删除失败，此商户不存在");
        Assert.isTrue(merchant.getIsDelete()==0, "删除失败，此商户已删除");

        //商户下面关联商户不可删
        QueryWrapper<Product> productQuery = new QueryWrapper<>();
        productQuery.eq("merchant_code", merchant.getMerchantCode());
        productQuery.eq("is_delete", 0);
        List<Product> list = productMapper.selectList(productQuery);
        Assert.isTrue(CollectionUtils.isEmpty(list), "此商户已关联商品不能删除");
        merchant.setLastUpdDt(LocalDateTime.now());
        merchant.setLastUpdBy(UserUtils.currentUserId());
        merchant.setIsDelete(1);

        //删除支付渠道
        updateDelChannel(merchant.getMerchantCode());

        return merchantMapper.updateById(merchant);
    }

    private int updateDelChannel(String merchantCode) {
        MerchantPaymentChannel channel = new MerchantPaymentChannel();
        channel.setLastUpdDt(LocalDateTime.now());
        channel.setLastUpdBy(UserUtils.currentUserId());
        channel.setIsDelete(1);
        QueryWrapper<MerchantPaymentChannel> conditions = new QueryWrapper<MerchantPaymentChannel>();
        conditions.eq("merchant_code", merchantCode);
        try {
            for (PaymentChannelEnum value : PaymentChannelEnum.values()) {
                merchantCache.isExistCachePaymentMerchant(merchantCode, value.getCode()).ifPresent(b -> {
                    if (b) {
                        merchantCache.delCachePaymentMerchant(merchantCode, value.getCode());
                    }
                });
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return channelMapper.update(channel, conditions);
    }

    /**
     * 按名字查询商户编号或名称是否存在
     *
     * @param merchantVO
     * @return
     * @throws BusinessException
     */
    private List<Merchant> findMerchantByCodeName(Merchant merchantVO) throws BusinessException {
        QueryWrapper<Merchant> conditions = new QueryWrapper<Merchant>();
        conditions.eq("is_delete", "0");
        if (null != merchantVO.getId()) {
            conditions.ne("id", merchantVO.getId());
        }
//        if (StringUtils.isNotEmpty(merchantVO.getMerchantName())) {
//            conditions.eq("merchant_name", merchantVO.getMerchantName());
//        }
        if (StringUtils.isNotEmpty(merchantVO.getMerchantName()) && StringUtils.isNotEmpty(merchantVO.getMerchantCode())) {
            conditions.and(wrapper -> wrapper.eq("merchant_name", merchantVO.getMerchantName()).or().eq("merchant_code", merchantVO.getMerchantCode()));
        }
        List<Merchant> list = merchantMapper.selectList(conditions);
        return list;
    }

    /**
     * 按组织编号查询商户list信息
     *
     * @param merchantVO
     * @return
     * @throws BusinessException
     */
    @Override
    public List<Merchant> findMerchantByOrgCode(GetMerchantVO merchantVO) throws BusinessException {
        return findBaseMerchantList(merchantVO);
    }

    /**
     * 根据业务侧商户编号，查询商户信息
     *
     * @param channelVO
     * @return
     * @throws BusinessException
     */
    @Override
    public List<MerchantPaymentChannelVO> findMerchantByBusiness(MerchantPaymentChannelVO channelVO) throws BusinessException {
        return channelMapper.findMerchantByBusiness(channelVO);
    }

    /**
     * 商户信息导出
     *
     * @param merchantVO
     * @param request
     * @param response
     * @throws IOException
     */
    public void export(GetPageMerchantVO merchantVO, HttpServletRequest request, HttpServletResponse response) throws IOException {

        List<MerchantExpVO> list = merchantMapper.getMerchantExport(merchantVO);
        list.forEach(merchant -> {
            if (StringUtils.isNotEmpty(merchant.getAccountType())) {
                merchant.setAccountType(MerchantAccountTypeEnum.getDescByCode(merchant.getAccountType()));
            }
            if (StringUtils.isNotEmpty(merchant.getScene())) {
                StrBuilder sb = new StrBuilder();
                for (String s : merchant.getScene().split(",")) {
                    sb.append(MerchantScenarioEnum.getDescByCode(s)).append(" ");
                }
                merchant.setScene(sb.toString().trim().replace(" ", ","));
            }
            if (StringUtils.isNotEmpty(merchant.getSettlementType())) {
                merchant.setSettlementType(SettlementTypeEnum.getDesc(merchant.getSettlementType()));
            }
        });
        List<Map<String, Object>> mapList = listConvert(list);

        String fileName = "商户信息.xlsx";

        String[] title = {"机构名称", "商户编码", "商户名称", "开户行", "开户名", "结算账户类型", "账号", "城市", "备注", "业务场景", "结算类型"};
        Workbook workbook = ExcelUtil.buildWorkbook("商户信息", title, mapList);

        ExcelUtil.exportExcle(request, response, workbook, fileName);
    }

    @Override
    public List<Merchant> getMerchantByMerCode(List<String> merchantCodes) throws BusinessException {
        return merchantMapper.getMerchantByMerCode(merchantCodes);
    }

    /**
     * 数据转换
     *
     * @param list
     * @return
     */
    private List<Map<String, Object>> listConvert(List<MerchantExpVO> list) {
        List<Map<String, Object>> list_map = new ArrayList<Map<String, Object>>();
        try {
            for (MerchantExpVO t : list) {
                Field[] fields = t.getClass().getDeclaredFields();
                Map<String, Object> m = new LinkedHashMap<String, Object>();
                for (Field field : fields) {
                    String keyName = field.getName();
                    PropertyDescriptor pd = new PropertyDescriptor(keyName, t.getClass());
                    Method getMethod = pd.getReadMethod();// 获得getter方法
                    Object o = getMethod.invoke(t);// 执行get方法返回一个Object
                    m.put(keyName, o);
                }
                list_map.add(m);
            }
            return list_map;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 根据商户名称模糊查询商户信息
     *
     * @param merchantName
     * @return
     * @throws BusinessException
     */
    @Override
    public List<GetMerchantVO> getMerchantsByName(String merchantName) throws BusinessException {
        QueryWrapper<Merchant> condition = new QueryWrapper<>();
        condition.like("merchant_name", merchantName);
        List<Merchant> list = merchantMapper.selectList(condition);
        Assert.isTrue(!CollectionUtils.isEmpty(list), "无商户信息");
        List<GetMerchantVO> reList = list.stream().map(s -> {
            GetMerchantVO getMerchantVO = new GetMerchantVO();
            BeanUtils.copyProperties(s, getMerchantVO);
            return getMerchantVO;
        }).collect(Collectors.toList());
        return reList;
    }

    /**
     * 根据商户编码和支付渠道编码查询商户信息（批量）
     *
     * @param list
     */
    @Override
    public List<MerchantWithChannelDTO> listByMerchantCodeAndChannel(List<GetMerchantPaymentVO> list) {
        List<MerchantWithChannelDTO> resultList = new ArrayList<>();
        // 以渠道分组，减少数据库访问次数 key=paymentChannelCode
        Map<String, List<GetMerchantPaymentVO>> group = list.stream().collect(Collectors.groupingBy(GetMerchantPaymentVO::getPaymentChannelCode));
        group.forEach((k, v) -> {
            List<MerchantWithChannelDTO> mList = merchantMapper.listByMerchantCodeAndChannel(k, v);
            resultList.addAll(mList);
        });

        if (resultList.size() > 0) {
            return resultList;
        }

        return null;
    }

    @Override
    public List<MerchantPaymentChannel> getMerchantPaymentChannelByMerchantCode(String merchantCode) {
        List<MerchantPaymentChannel> mChanals = channelMapper.getChannelByMerchantCode(Collections.singletonList(merchantCode));
        if (org.apache.commons.collections4.CollectionUtils.isNotEmpty(mChanals)) {
            Result<List<PaymentChannelResponseDTO>> channelBOList = paymentFeignService.getAllChannel();
            List<PaymentChannelResponseDTO> channelList = new ArrayList<PaymentChannelResponseDTO>();
            if (channelBOList.getRet() == 0) {
                channelList = channelBOList.getData();
            }
            List<PaymentChannelResponseDTO> finalChannelList = channelList;
            mChanals.forEach(channel -> {
                List<PaymentChannelResponseDTO> filterList = finalChannelList.stream().filter(c -> c.getPaymentChannelCode().equals(channel.getPaymentChannelCode())).collect(Collectors.toList());
                if (CollectionUtils.isNotEmpty(filterList)) {
                    channel.setPaymentChannelName(filterList.get(0).getPaymentChannelName());
                }
            });
        }
        return mChanals;
    }

    @Override
    public List<AllMerchantResVo> findOnlyMerchantList(GetMerchantVO merchantVO) {
        List<Merchant> list = this.findBaseMerchantList(merchantVO);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.stream().map(m -> {
                AllMerchantResVo target = new AllMerchantResVo();
                BeanUtils.copyProperties(m, target);
                return target;
            }).collect(Collectors.toList());
        }
        return Collections.emptyList();
    }

    /**
     * 根据交易中台 商户编号 商户信息和支付渠道信息
     *
     * @param list {@link List}<{@link String}> 交易中台商品编号列表
     * @return {@link List}<{@link MerchantPaymentChannelVO}> 商品和支付渠道信息列表
     */
    @Override
    public List<MerchantPaymentChannelVO> findPaymentChannelByMerchantCodes(List<String> list) {
        return merchantMapper.findPaymentChannelByMerchantCodes(list);
    }

    @Override
    public List<CommonMerchantVO> getMerchantByCreateDate(LocalDate today) {
        LocalDateTime start = LocalDateTime.of(today.getYear(), today.getMonth(), today.getDayOfMonth(), 0, 0, 0);
        LocalDateTime end = LocalDateTime.of(today.getYear(), today.getMonth(), today.getDayOfMonth(), 23, 59, 59);
        final QueryWrapper<Merchant> queryWrapper = new QueryWrapper<>();
        queryWrapper.between("created_dt",start,end);
        queryWrapper.select("merchant_code","merchant_name");
        final List<Merchant> merchants = merchantMapper.selectList(queryWrapper);
        if(org.springframework.util.CollectionUtils.isEmpty(merchants)){
            return Collections.emptyList();
        }
        final List<CommonMerchantVO> merchantList = new ArrayList<>();
        for (Merchant merchant : merchants) {
            merchantList.add(new CommonMerchantVO(merchant.getMerchantCode(), merchant.getMerchantName()));
        }
        return merchantList;
    }

    @Override
    public List<QueryOrderMerchantResVO> queryOrderMerchant(QueryOrderMerchantReqVO queryOrderMerchantReqVO) {
        return merchantMapper.queryOrderMerchant(queryOrderMerchantReqVO);
    }

}
